package cn.wzy.controller;



import cn.wzy.annotation.AnPermission;
import cn.wzy.pojo.Shop;
import cn.wzy.results.ResponseResult;
import cn.wzy.service.ShopService;
import cn.wzy.vo.ApprovedVO;
import cn.wzy.vo.GoPageVo;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.annotation.TableName;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Shop)表控制层
 *
 * @author makejava
 * @since 2023-01-09 17:38:56
 */
@RestController
@RequestMapping("shop")
@ApiOperation(value = "店铺管理")
@AnPermission(name = "店铺管理")
public class ShopController{
    /**
     * 服务对象
     */
    @Resource
    private ShopService shopService;
    
    /*
    * 查询分页
    * */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询",tags = "分页")
    @AnPermission(name = "分页查询")
    public ResponseResult getShopPage(@RequestBody GoPageVo goPageVo){
        return shopService.getShopPage(goPageVo);
    }

    /*
    * 查询
    * */
    @GetMapping("/{id}")
    @AnPermission(name = "id查询")
    @ApiOperation(value = "id查询")
    public ResponseResult getShop(@PathVariable("id") Long id){
        return shopService.getShop(id);
    }

    /*
    * 新增和修改
    * */
    @PostMapping
    @AnPermission(name = "??修改或者添加")
    @ApiOperation(value = "新增或者修改")
    public ResponseResult saveShop(@RequestBody Shop shop){
        return shopService.saveShop(shop);
    }

    /*
    * 删除
    * */
    @DeleteMapping("/{id}")
    @AnPermission(name = "id删除")
    @ApiOperation(value = "删除部门")
    public ResponseResult deleteShop(@PathVariable("id") Long id){
        return shopService.deleteShop(id);
    }


    /*
    * 批量删除
    * */
    @PatchMapping
    @AnPermission(name = "批量删除")
    @ApiOperation(value = "批量删除")
    public ResponseResult deleteShopList(@RequestBody List<Long> ids){
        return shopService.deleteShopList(ids);
    }


    /*
    * 商家入住
    * */
    @PostMapping("/settlement")
    @ApiOperation(value ="商家入住")
    @AnPermission(name = "商家入住")
    public ResponseResult settlement(@RequestBody Shop shop){
        try {
            shopService.settlement(shop);
            return ResponseResult.okResult();
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(400,"店铺入驻失败！"+e.getMessage());
        }
    }

    /*
    * 激活入住商家
    * */
    @GetMapping("/activation/{shopId}/{uuid}")
    @ApiOperation(value ="商家入住")
    @AnPermission(name = "商家入住")
    public ResponseResult activation(@PathVariable("shopId")Long shopId,@PathVariable("uuid") String uuid){
        return  shopService.activation(shopId,uuid);
    }

    /*
    * 手动审核通过
    * */
    @PostMapping("/approved")
    @ApiOperation(value ="手动审核通过")
    @AnPermission(name = "手动审核通过")
    public ResponseResult approved(@RequestBody ApprovedVO approvedVO){
        return shopService.approved(approvedVO);
    }
    /*
    * 手动审核失败
    * */
    @PostMapping("/auditFailed")
    @ApiOperation(value ="手动审核失败")
    @AnPermission(name = "手动审核失败")
    public ResponseResult auditFailed(@RequestBody ApprovedVO approvedVO){
        return shopService.auditFailed(approvedVO);
    }
}

